package com.sensePlusVR.realGame;

import java.util.List;

import android.util.Log;

public class RealGameControllerV2 {
	private static final String TAG = "RealGameControllerV2";
		
	private static final int HeighSpeed = 8;
	private static final int MidSpeed   = 13;
	
	private RealGameConfigV2 mCurrentGame;
	private int currentAction;
	List<Action> actions;
	public RealGameControllerV2(String configfile){
		Log.e(TAG, "configfile="+configfile);
		mCurrentGame = new RealGameConfigV2(configfile);
		currentAction = 0;
		actions = mCurrentGame.actions();
	}
	
	public void LastAction(){
		currentAction = actions.size() - 1;
	}
	
	public void NextAction(){
		Log.e(TAG, "NextAction");
		currentAction = (currentAction + 1) % actions.size();

		Log.e(TAG, "NextAction end");
	}
	
	public String getStartVideo(){
		return mCurrentGame.startVideo();
	}
	
	public String getEndVideo(){
		return mCurrentGame.endVideo();
	}
	
	public String getBackAudioFile(){
		String file = mCurrentGame.getBackAudio();;
		Log.e(TAG, "backaudio="+file);
		return file;
	}
	
	public void setCurrentMinor(int minor){
		Action action = actions.get(currentAction);
		action.setMinor(minor);
	}
	
	public void changeMinor(){
		Action action = actions.get(currentAction);
		action.ChangeMinor();
	}
	
	public String getCurrentAction(){
		String s = null;
		Action action = actions.get(currentAction);
		String sact = action.toString();
		if (sact == null){
			Log.e(TAG, "Maybe this is video action");
			return null;
		}
		s = String.format("V%d:", getConfigVersion()) + sact;
		Log.e(TAG, "getCurrentAction="+s);
		return s;
	}
	
	public String getCurrentDesVideo()
	{
		Action action = actions.get(currentAction);
		return action.video();
	}
	
	public int getStep(int speed){
		if (speed == 0)
			return AudioLevel.IDLE;
		else if (speed <= HeighSpeed)
			return AudioLevel.HEIGH;
		else if (speed <= MidSpeed)
			return AudioLevel.MID;
		else
			return AudioLevel.LOW;
	}
	
	public String getSound(int step){
		Action action = actions.get(currentAction);
		String file = null;
		if (step == AudioLevel.IDLE)
			file = action.getIdleAudio();
		else if (step == AudioLevel.HEIGH)
			file = action.getFastAudio();
		else if (step == AudioLevel.MID)
			file = action.getMidAudio();
		else
			file = action.getLowAudio();
		//Log.e(TAG, "getaudio file="+file);
		return file;
	}
	
	public boolean supportVideo(){
		return mCurrentGame.supportVideo();
	}
	
	public int getSourceType()
	{
		if (mCurrentGame != null)
			return mCurrentGame.sourceType();
		return 0;
	}
	
	public int getConfigVersion()
	{
		if (mCurrentGame != null)
			return mCurrentGame.version();
		return 0;
	}
}
